<template>
  <div class="app-container">

    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="订单号: ">
        <el-input v-model="orderQuery.orderNo" placeholder="输入订单号"/>
      </el-form-item>
      <el-form-item label="用户手机号: ">
        <el-input v-model="orderQuery.mobile" placeholder="输入用户手机号"/>
      </el-form-item>
      <el-form-item label="课程名称: ">
        <el-input v-model="orderQuery.courseTitle" placeholder="输入课程名称"/>
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <el-table
      :data="orderList"
      border
      fit
      :header-cell-style="{background:'#0078AD',color:'#FFFFFF'}"
      highlight-current-row>

      <el-table-column
        label="序号"
        align="center">
        <!-- slot-scope="scope" 属性本质就是一个插槽 -->
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="orderNo" label="订单号" />
      <el-table-column prop="courseTitle" label="课程名称" />
      <el-table-column prop="teacherName" label="主讲教师" />
      <el-table-column prop="nickname" label="用户昵称" />
      <el-table-column prop="mobile" label="用户手机" />
      <el-table-column prop="totalFee" label="支付金额(元)" />
      <el-table-column label="支付类型">
        <template slot-scope="scope">
          {{ scope.row.payType===1?'微信支付':'支付宝支付' }}
        </template>
      </el-table-column>
      <el-table-column prop="gmtModified" label="支付时间" />
      

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />


  </div>
</template>

<script>
import order from '@/api/edu/order'

export default {
    data() {
        return {
          orderList:null,//查询之后接口返回集合
          page:1,//当前页
          limit:5,//每页记录数
          total:0,//总记录数
          orderQuery:{} //条件封装对象
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList(page = 1) {
            this.page = page
            order.pageOrderCondition(this.page, this.limit, this.orderQuery)
                .then(response => {
                    this.orderList = response.data.rows
                    this.total = response.data.total
                })
                .catch(error => {
                    console.log(error)
                })
        },
        //清空条件查询内容
        resetData() {
            //清空内容
            this.orderQuery = {}
            //重新查询列表
            this.getList()
        },
        //删除
        removeDataById(id) {
            this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            //发起请求
            order.deleteOrderById(id)
                .then(response => {
                    this.getList((this.total % this.limit == 1 && this.page > 1 ? this.page - 1 : this.page))
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                })
          }).catch((response) => { // 失败
            if (response === 'cancel') {
              this.$message({
                type: 'info',
                message: '已取消删除'
              })
            }
          });
        },
    },
}

</script>
